#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

/* Notes:
  当 d== (1<<c), x是负数， x/d 并不等于(x>>c)
*/
void mod_128_test( int x)
{
    int m,y,x1;
    const char* fmt;

    m = x % 128;
    printf("x=%d,%d%%128=%d\n",x,x,m);

    y = x / 128;
    printf("case1: %d/128=%d,", x, y);    
    x1=y*128+m;
    printf("%d*128+%d=%d", y, m, x1);
    fmt= (x==x1)? " == x\n" : " != x\n";
    printf("%s",fmt);

    y = (x >> 7);
    printf("case2: %d>>7=%d,", x, y);    
    x1=y*128+m;
    printf("%d*128+%d=%d", y, m, x1);
    fmt= (x==x1)? " == x\n" : " != x\n";
    printf("%s",fmt);
}

void test_mod()
{
    printf("\nrun %s()\n",__func__);
    int x;
    int ary[] = {-129,-128,-127,-1,0, 127,128,129 };
    for (size_t i=0;i<sizeof(ary)/sizeof(ary[0]);i++)
    {
        x=ary[i];
        mod_128_test(x);
        printf("\n");
    }
}
int main(int argc, char* argv[])
{
    test_mod();
    return 0;
}
